x
breed [particles particle]breed [ion-channels ion-channel]particles-own [my-position charge]globals [ inside-cell outside-cell membrane-patches]ion-channels-own [my-type]to setup clear-all ; add sodium ions inside ask patches with [pxcor < -2] [ if random 100 < 10 [ sprout-particles 1 [ set shape "circle" set size 0.5 set color red fd random-float 1 set my-position "inside" set charge "positive" ] ] ] ; add sodium ions outside ask patches with [pxcor > 2] [ if random 100 < 98 [ sprout-particles 1 [ set shape "circle" set size 0.5 set color red fd random-float 1 set my-position "outside" set charge "positive" ] ] ] ; add chloride ions inside ask patches with [pxcor < -2] [ if random 100 < 9 [ sprout-particles 1 [ set shape "circle" set size 0.5 set color green fd random-float 1 set my-position "inside" set charge "negative" ] ] ] ; add chloride ions outside ask patches with [pxcor > 2] [ if random 100 < 100 [ sprout-particles 1 [ set shape "circle" set size 0.5 set color green fd random-float 1 set my-position "outside" set charge "negative" ] ] ] ; add potassium ions inside ask patches with [pxcor < -2] [ if random 100 < 83 [ sprout-particles 1 [ set shape "circle" set size 0.5 set color yellow fd random-float 1 set my-position "inside" set charge "positive" ] ] ] ; add potassium ions outside ask patches with [pxcor > 2] [ if random 100 < 3 [ sprout-particles 1 [ set shape "circle" set size 0.5 set color yellow fd random-float 1 set my-position "outside" set charge "positive" ] ] ] ; make chambers ask patches with [pxcor < 2 and pxcor > -2] [set pcolor blue] ; patches that can have ion-channels set membrane-patches patches with [pxcor = 0 and (pycor < max-pycor - 1) and (pycor > min-pycor + 1)] ; make sodium channels ask n-of 5 membrane-patches [sprout-ion-channels 1 [ set size 4 set heading 180 set my-type "Na-channel" set color red set shape "open Ion Channel" ] ] ; make choloride channels ask n-of 5 membrane-patches with [count ion-channels-here = 0 ] [sprout-ion-channels 1 [ set size 4 set heading 180 set my-type "Cl-channel" set color green set shape "open Ion Channel" ] ] ; make potassium channels ask n-of 5 membrane-patches with [count ion-channels-here = 0 ] [sprout-ion-channels 1 [ set size 4 set heading 180 set my-type "K-channel" set color yellow set shape "open Ion Channel" ] ] set inside-cell patches with [pxcor < 0 and pcolor = black] set outside-cell patches with [pxcor > 0 and pcolor = black] reset-ticksendto random-walk ; take a step forward through fractional distance less than 1 fd random-float 1 ;randomize direction (heading) for the next step rt random 360endto go ifelse trace-path? [ ask particles [pen-down] ] [ ask particles [pen-up] ] ask particles [ ; if you are near a blue wall or an edge , turn back, else do the random walk if my-position = "inside" [ if patch-ahead 1 = nobody [ set heading 90 fd 1 ] if [pcolor] of patch-ahead 1 = blue [ set heading 270 fd 1 ] ] if my-position = "outside" [ if patch-ahead 1 = nobody [ set heading 270 fd 1 ] if [pcolor] of patch-ahead 1 = blue [ set heading 90 fd 1 ] ] random-walk ; additional movement because of the charges if strength-of-the-field > 0 [ if charge = "positive" [ if (xcor + strength-of-the-field) < max-pxcor [ ; to make sure that the particle does not move beyod the edge of the world set xcor (xcor + strength-of-the-field) ] ] if charge = "negative" [ if (xcor - strength-of-the-field) > min-pxcor [ ; to make sure that the particle does not move beyod the edge of the world set xcor (xcor - strength-of-the-field) ] ] ] if strength-of-the-field < 0 [ if charge = "positive" [ if (xcor + strength-of-the-field) > min-pxcor [ ; to make sure that the particle does not move beyod the edge of the world set xcor (xcor + strength-of-the-field) ] ] if charge = "negative" [ if (xcor - strength-of-the-field) < max-pxcor [ ; to make sure that the particle does not move beyod the edge of the world set xcor (xcor - strength-of-the-field) ] ] ] ] ; transport Na outside to inside and inside to outside ; inside to outside ask ion-channels with [my-type = "Na-channel"] [ if any? particles in-radius 3 with [my-position = "inside" and color = red] [ if random-float 1 < Na-transportation-probability [ let destination-patches (outside-cell in-radius 2) ask one-of particles in-radius 3 with [my-position = "inside" and color = red ] [ move-to one-of destination-patches set my-position "outside" ] ] ] ; outside to inside if any? particles in-radius 3 with [my-position = "outside" and color = red] [ if random-float 1 < Na-transportation-probability [ let destination-patches (inside-cell in-radius 2) ask one-of particles in-radius 3 with [my-position = "outside" and color = red ] [ move-to one-of destination-patches set my-position "inside" ] ] ] ] ; transport Cl outside to inside and inside to outside ; inside to outside ask ion-channels with [my-type = "Cl-channel"] [ if any? particles in-radius 3 with [my-position = "inside" and color = green] [ if random-float 1 < Cl-transportation-probability [ let destination-patches (outside-cell in-radius 2) ask one-of particles in-radius 3 with [my-position = "inside" and color = green ] [ move-to one-of destination-patches set my-position "outside" ] ] ] ; outside to inside if any? particles in-radius 3 with [my-position = "outside" and color = green] [ if random-float 1 < Cl-transportation-probability [ let destination-patches (inside-cell in-radius 2) ask one-of particles in-radius 3 with [my-position = "outside" and color = green ] [ move-to one-of destination-patches set my-position "inside" ] ] ] ] ; transport K outside to inside and inside to outside ; inside to outside ask ion-channels with [my-type = "K-channel"] [ if any? particles in-radius 3 with [my-position = "inside" and color = yellow] [ if random-float 1 < Cl-transportation-probability [ let destination-patches (outside-cell in-radius 2) ask one-of particles in-radius 3 with [my-position = "inside" and color = yellow ] [ move-to one-of destination-patches set my-position "outside" ] ] ] ; outside to inside if any? particles in-radius 3 with [my-position = "outside" and color = yellow] [ if random-float 1 < Cl-transportation-probability [ let destination-patches (inside-cell in-radius 2) ask one-of particles in-radius 3 with [my-position = "outside" and color = yellow ] [ move-to one-of destination-patches set my-position "inside" ] ] ] ] tickend